﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.IRepositorys.DB;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.DB
{   /// <summary>
    /// 仓库控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]

    public class Db_warehouseController : ControllerBase
    {
        private readonly IMapper mapper;
        private readonly IDb_warehouseServices db_warehouseServices;

        public Db_warehouseController(IDb_warehouseServices db_warehouseServices, IMapper mapper)
        {
            this.db_warehouseServices = db_warehouseServices;
            this.mapper = mapper;
        }


        /// <summary>
        /// 查询总条数(调用Appliaction)
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="warehouse_name"></param>
        /// <returns></returns>
        [HttpGet]
        public int warehouseCount(string? warehouse_code, string? warehouse_name) {
            return db_warehouseServices.Select_count_warehouse(warehouse_code, warehouse_name);
        }

        /// <summary>
        /// 仓库分页查询(调用Appliaction)
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="warehouse_name"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult WarehouseFY(string? warehouse_code, string? warehouse_name, int currentPage, int pageSize) {
            //JsonResult--将数据封装成json格式返回给前端
            return new JsonResult(db_warehouseServices.Select_fy_warehouse(warehouse_code, warehouse_name, currentPage, pageSize));
        }


        /// <summary>
        /// 仓库信息逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns
        [HttpPut]
        public async Task<IActionResult> Warehousetombstone(string warehouse_code) {
            return new JsonResult(await db_warehouseServices.warehouse_tombstone(warehouse_code));
        }


      
        [HttpPut]
        public async Task<IActionResult> WarehouseFrozenstate(int id, char Warehouse_freeze)
        {
            return new JsonResult(await db_warehouseServices.warehouse_Frozenstate(id, Warehouse_freeze));
        }

        /// <summary>
        /// 仓库编码唯一性判断
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception> 
        [HttpGet]
        public Task<int> WarehouseCodeJudgment(string warehouse_code)
        {
            return db_warehouseServices.Warehouse_code_judgment(warehouse_code);
        }
        /// <summary>
        /// 仓库名称唯一性判断
        /// </summary>
        /// <param name="warehouse_name"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        
        public Task<int> WarehouseNameJudgment(string warehouse_name)
        {
            return db_warehouseServices.Warehouse_name_judgment(warehouse_name);
        }
        /// <summary>
        /// 仓库添加
        /// </summary>
        /// <param name="db_MeasureAddDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Db_warehouseAdd([FromBody] Db_warehouseAddDto db_MeasureAddDto) {
            //FromBody从 HTTP 请求的请求体（Body）中反序列化获取。
            return new JsonResult(await db_warehouseServices.Warehouse_add(db_MeasureAddDto));
        }
        /// <summary>
        /// 修改仓库信息
        /// </summary>
        /// <param name="db_MeasureUpdateDto"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public async Task<JsonResult> Db_warehouseUpdate([FromBody] Db_warehouseUpdateDto db_MeasureUpdateDto) {
            return new JsonResult(await db_warehouseServices.Warehouse_update(db_MeasureUpdateDto));
        }
        
        /// <summary>
        /// 分页条件查询产品库存信息
        /// </summary>
        /// <param name="productName"></param>
        /// <param name="dict_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetInv_StockAsync(string? productName, int dict_code, int currentPage, int pageSize)
        {
            return new JsonResult(await db_warehouseServices.GetInv_StockAsync(productName,dict_code,currentPage,pageSize));
        }

        /// <summary>
        /// 条件查询产品信息总数
        /// </summary>
        /// <param name="productName"></param>
        /// <param name="dict_code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Inv_StockCountAsync(string? productName, int dict_code)
        {
            return new JsonResult(await db_warehouseServices.Inv_StockCountAsync(productName,dict_code));
        }

        /// <summary>
        /// 根据产品编号查询产品库存信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetInv_StockByCodeAsync(string code)
        {
            return new JsonResult(await db_warehouseServices.GetInv_StockByCodeAsync(code));
        }

        /// <summary>
        /// 根据产品编号库位查询产品库存信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetInv_StockByCodeLocationCodeAsync(string code, string LocationCode)
        {
            return new JsonResult(await db_warehouseServices.GetInv_StockByCodeLocationCodeAsync(code, LocationCode));
        }



        /// <summary> 
        /// 查询全部信息 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult WarehouseBySelectAsync()
        {
            return new JsonResult (db_warehouseServices.WarehouseBy_Select_Async());
        }



        /// <summary>
        /// 结构编码查询仓库信息
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult WarehouseBy_Select_Async_code(string warehouse_code)
        {

         return new JsonResult (db_warehouseServices.WarehouseBy_Select_Async_code(warehouse_code));
        }
        /// <summary>
        /// 查询全部信息--盘点
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult WarehouseBy_Selectpd()
        {
            return new JsonResult(db_warehouseServices.WarehouseBy_Selectpd());
        }


        /// <summary>
        /// 根据传递的参数修改仓库关联信息
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="zone_code"></param>
        /// <param name="location_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Warehouse_update_liaison(List<Db_Weahouse_capacityUpdateDto> db_Weahouse_CapacityUpdateDtos)
        {
            return db_warehouseServices.Warehouse_update_liaison(db_Weahouse_CapacityUpdateDtos);
        }
        /// <summary>
        ///  修改仓库内量--增加
        /// </summary>
        /// <param name="db_Weahouse_CapacityUpdateDtos"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Warehouse_update_liaison_newly(List<Db_Weahouse_capacityUpdateDto> db_Weahouse_CapacityUpdateDtos)
        {
            return db_warehouseServices.Warehouse_update_liaison_newly(db_Weahouse_CapacityUpdateDtos);
        }



        /// <summary>
        /// 修改的时候,仓库名称唯一性判断
        /// </summary>
        /// <param name="warehouse_name"></param>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Warehouse_name_UpdateJudgment(string warehouse_name, string warehouse_code)
        {


            return db_warehouseServices.Warehouse_name_UpdateJudgment(warehouse_name, warehouse_code);
        }
    }
    
}
